*/ public function register(): array { return [ T_STATIC, ]; } /** * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @param int $staticPointer */ public function process(File $phpcsFile, $staticPointer): void { $tokens = $phpcsFile->getTokens(); $doubleColonPointer = TokenHelper::findNextEffective($phpcsFile, $staticPointer + 1); if ($tokens[$doubleColonPointer]['code'] !== T_DOUBLE_COLON) { return; } $classPointer = null; foreach (array_reverse($tokens[$staticPointer]['conditions'], true) as $conditionPointer => $conditionTokenCode) { if (!in_array($conditionTokenCode, Tokens::$ooScopeTokens, true)) { continue; } $classPointer = $conditionPointer; break; } if ($classPointer === null || !ClassHelper::isFinal($phpcsFile, $classPointer)) { return; } $fix = $phpcsFile->addFixableError( 'Useless late static binding because class is final.', $staticPointer, self::CODE_USELESS_LATE_STATIC_BINDING, ); if (!$fix) { return; } $phpcsFile->fixer->beginChangeset(); FixerHelper::replace($phpcsFile, $staticPointer, 'self'); $phpcsFile->fixer->endChangeset(); } }